package com.ruoyi.seedlingSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.seedlingSys.domain.TemperatureHumidity;
import com.ruoyi.seedlingSys.service.ITemperatureHumidityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 温湿度管理Controller
 * 
 * @author ruoyi
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/seedlingSys/humidity")
public class TemperatureHumidityController extends BaseController
{
    @Autowired
    private ITemperatureHumidityService temperatureHumidityService;

    /**
     * 查询温湿度管理列表
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:humidity:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemperatureHumidity temperatureHumidity)
    {
        startPage();
        List<TemperatureHumidity> list = temperatureHumidityService.selectTemperatureHumidityList(temperatureHumidity);
        return getDataTable(list);
    }

    /**
     * 导出温湿度管理列表
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:humidity:export')")
    @Log(title = "温湿度管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TemperatureHumidity temperatureHumidity)
    {
        List<TemperatureHumidity> list = temperatureHumidityService.selectTemperatureHumidityList(temperatureHumidity);
        ExcelUtil<TemperatureHumidity> util = new ExcelUtil<TemperatureHumidity>(TemperatureHumidity.class);
        util.exportExcel(response, list, "温湿度管理数据");
    }

    /**
     * 获取温湿度管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:humidity:query')")
    @GetMapping(value = "/{thId}")
    public AjaxResult getInfo(@PathVariable("thId") Long thId)
    {
        return success(temperatureHumidityService.selectTemperatureHumidityByThId(thId));
    }

    /**
     * 新增温湿度管理
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:humidity:add')")
    @Log(title = "温湿度管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TemperatureHumidity temperatureHumidity)
    {
        return toAjax(temperatureHumidityService.insertTemperatureHumidity(temperatureHumidity));
    }

    /**
     * 修改温湿度管理
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:humidity:edit')")
    @Log(title = "温湿度管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemperatureHumidity temperatureHumidity)
    {
        return toAjax(temperatureHumidityService.updateTemperatureHumidity(temperatureHumidity));
    }

    /**
     * 删除温湿度管理
     */
    @PreAuthorize("@ss.hasPermi('seedlingSys:humidity:remove')")
    @Log(title = "温湿度管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{thIds}")
    public AjaxResult remove(@PathVariable Long[] thIds)
    {
        return toAjax(temperatureHumidityService.deleteTemperatureHumidityByThIds(thIds));
    }
}
